package name.fowler.refactoring.simplestore;

public class Rental {
	private Movie movie;
	private int daysRented;

	public Rental(Movie movie, int daysRented) {
		this.movie = movie;
		this.daysRented = daysRented;
	}

	public int getDaysRented() {
		return daysRented;
	}

	public Movie getMovie() {
		return movie;
	}

	public double getRentalAmount() {
		switch (getMovie().getPriceCode()) {
		case Regular:
			return getRegularRentalPrice();
		case NewRelease:
			return getNewReleaseRentalPrice();
		case Children:
			return getChildrenRentalPrice();
		default:
			throw new IllegalArgumentException("Unknown movie type");

		}
	}

	private double getChildrenRentalPrice() {
		double rentalAmount = 1.5;
		if (getDaysRented() > 3) {
			rentalAmount = (getDaysRented() - 3) * 1.5;
		}
		return rentalAmount;
	}

	private double getNewReleaseRentalPrice() {
		return getDaysRented() * 3;
	}

	private double getRegularRentalPrice() {
		double rentalAmount = 2;
		if (getDaysRented() > 2) {
			rentalAmount += (getDaysRented() - 2) * 1.5;
		}
		return rentalAmount;
	}
}
